'use strict'

const Service = require('egg').Service

class NewsService extends Service {
  /**
   * @param {Number} index 列表数组标志，默认 0
   */
  async getNewsList() {
    const apiUrl =
      this.config.testApiUrl + '/appapi.php?a=getPortalList&catid=20&page=1'

    // curl 是 egg.js 内置的访问外网的请求方法
    const { data } = await this.ctx.curl(apiUrl)
    const obj = JSON.parse(data)
    obj.result.forEach((element) => {
      element.dateline_format = this.ctx.helper.formatTime(element.dateline)
    })
    return obj
  }
  async testPost(postBody) {
    return {
      a: 123,
      postBody,
    }
  }
}

module.exports = NewsService
